# -*- coding: utf-8 -*-
"""
@Time : 2023/6/11 21:40
@Author : Gremore
@File : calendar
@Des: 
"""

from datetime import datetime
from sqlalchemy import Column, String, INT, DATETIME, SMALLINT, func, Boolean
from tsim.models import Base
from tsim.commons.enums import PermissionEnum
from tsim.routers.plan.request_model import CalendarBody

class CalendarTab(Base):
    __tablename__ = "calendar_tab"

    id = Column(INT, primary_key=True, comment="主键id")
    title = Column(String(128), nullable=True, comment="标题")
    start_time = Column(DATETIME, nullable=False, default=946656000, comment="开始时间")
    end_time = Column(DATETIME, nullable=False, default=946656000, comment="结束时间")
    create_time = Column(DATETIME, nullable=False, comment="创建时间")
    update_time = Column(DATETIME, onupdate=func.now(), nullable=False, comment="更新时间")

    def __init__(self, form: CalendarBody):
        self.title = form.title
        self.start_time = datetime.fromtimestamp(form.start_time)
        self.end_time = datetime.fromtimestamp(form.end_time)
        self.create_time = datetime.now()
        self.update_time = datetime.now()